﻿using System;

namespace Qiao.Common.Core
{
    /// <summary>
    /// 枚举类型帮助类
    /// </summary>
    public class EnumExtend
    {

        #region String To Enum
        /// <summary>
        /// String To Enum
        /// </summary>
        /// <param name="enumType">枚举类型</param>
        /// <param name="value">字符串值</param>
        /// <returns>成功返回这个枚举 如果该字符串不存在则抛异常</returns>
        public static object StringToEnum(Type enumType, string value)
        {
            return Enum.Parse(enumType, value);
        }

        /// <summary>
        /// String To Enum
        /// </summary>
        /// <param name="enumType">枚举类型</param>
        /// <param name="value">字符串值</param>
        /// <returns>成功返回这个枚举 失败返回null</returns>
        public static object TryStringToEnum(Type enumType, string value)
        {
            object obj = null;
            try
            {
                obj = Enum.Parse(enumType, value);
            }
            catch (Exception e)
            {

            }
            return obj;
        }
        #endregion

    }
}
